package firstcontent.rabbitcollect;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class StopTheWorldTest1 {

    public static class printSecond extends Thread{
        public void run(){
            long start = System.currentTimeMillis();

            while(true){
                long per = System.currentTimeMillis();
                long dif = per-start;
                System.out.println(dif/1000+"."+dif%1000);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static class addNum extends Thread{
        public void run(){
            List<byte[]> list = new ArrayList<>();
            while(true){
                for(int i = 0;i<1000;i++){
                    byte[] bytes = new byte[1024];
                    list.add(bytes);
                }
                if(list.size()>10000){
                    list.clear();
                    System.gc();
                }
            }
        }
    }

    public static void main(String[] args) {
        Thread t1 = new printSecond();

        Thread t2 = new addNum();
        t2.start();
        t1.start();
    }
}
